#include "XMLCommonLoader.h"

#pragma warning(disable:4390)
#pragma warning(disable:4305)

XMLCommonLoader::XMLCommonLoader(void)
{
}

XMLCommonLoader::~XMLCommonLoader(void)
{
}

Ogre::String XMLCommonLoader::getAttrib(rapidxml::xml_node<>* XMLNode, const Ogre::String &attrib, const Ogre::String &defaultValue)
{
    if(XMLNode->first_attribute(attrib.c_str()))
        return XMLNode->first_attribute(attrib.c_str())->value();
    else
        return defaultValue;
}

Ogre::Real XMLCommonLoader::getAttribReal(rapidxml::xml_node<>* XMLNode, const Ogre::String &attrib, Ogre::Real defaultValue)
{
    if(XMLNode->first_attribute(attrib.c_str()))
        return Ogre::StringConverter::parseReal(XMLNode->first_attribute(attrib.c_str())->value());
    else
        return defaultValue;
}

Ogre::int32 XMLCommonLoader::getAttribInt(rapidxml::xml_node<>* XMLNode, const Ogre::String &attrib, Ogre::int32 defaultValue)
{
    if(XMLNode->first_attribute(attrib.c_str()))
		return Ogre::StringConverter::parseInt(XMLNode->first_attribute(attrib.c_str())->value());
    else
        return defaultValue;
}

bool XMLCommonLoader::getAttribBool(rapidxml::xml_node<>* XMLNode, const Ogre::String &attrib, bool defaultValue)
{
    if(!XMLNode->first_attribute(attrib.c_str()))
        return defaultValue;

    if(Ogre::String(XMLNode->first_attribute(attrib.c_str())->value()) == "true")
        return true;

    return false;
}
